//
//  MODoctorListCell.m
//  FastDoctor
//
//  Created by 冯龙飞 on 16/5/22.
//  Copyright © 2016年 冯龙飞. All rights reserved.
//

#import "MODoctorListCell.h"
#import "Masonry/Masonry.h"
#import "UIImageView+WebCache.h"
#import "MOConcernModel.h"

// 各个空间之间的间距
#define MOMargin 10

@interface MODoctorListCell ()
// 头像
@property(nonatomic, strong) UIImageView * icon;
// 医生名字
@property(nonatomic, copy) UILabel * name;
// 医生科目
@property(nonatomic, copy) UILabel * kind;
// 医院名称
@property(nonatomic, copy) UILabel * hospital;
// 右侧图片
@property(nonatomic, copy) UIImageView * pic;
// 加加图标
@property(nonatomic, strong) UIImageView * add;
// 个数
@property(nonatomic, copy) UILabel * addCount;
// 鲜花图标
@property(nonatomic, strong) UIImageView * flower;
// 鲜花个数
@property(nonatomic, copy) UILabel * flowerCount;
// 收藏图标
@property(nonatomic, strong) UIImageView * collect;
// 收藏个数
@property(nonatomic, copy) UILabel * collectCount;


@end

@implementation MODoctorListCell

// 在这个初始化方法中添加子控件
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self addSubview:self.icon];
        [self addSubview:self.name];
        [self addSubview:self.kind];
        [self addSubview:self.hospital];
        [self addSubview:self.pic];
        [self addSubview:self.add];
        [self addSubview:self.flower];
        [self addSubview:self.collect];
        [self addSubview:self.addCount];
        [self addSubview:self.flowerCount];
        [self addSubview:self.collectCount];
        
    }
    return self;
}

// 在模型的set方法中给属性赋值
- (void)setModel:(MOConcernModel *)model {
    
    _model = model;
    
    self.name.text = model.doctor_name;
    self.name.font = [UIFont systemFontOfSize:15];
    
    self.kind.text = model.doctor_title_name;
    self.kind.font = [UIFont systemFontOfSize:13];
    self.kind.textColor = [UIColor grayColor];
    
    self.hospital.text = model.doctor_hospital_name;
    self.hospital.font = [UIFont systemFontOfSize:13];
    self.hospital.textColor = [UIColor grayColor];
    
    self.pic.image = [UIImage imageNamed:@"jishiben"];
    self.add.image = [UIImage imageNamed:@"yuyueliang"];
    self.flower.image = [UIImage imageNamed:@"xianhua"];
    self.collect.image = [UIImage imageNamed:@"jinqi"];
    
    self.addCount.text = model.banner;
    self.addCount.font = [UIFont systemFontOfSize:12];
    
    self.flowerCount.text = model.flower;
    self.flowerCount.font = [UIFont systemFontOfSize:12];
    
    self.collectCount.text = model.operation_count;
    self.collectCount.font = [UIFont systemFontOfSize:12];
    
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.doctor_portrait]];
    
    // 判断,如果没有图片返回,就用占位图片代替
    if (!self.icon.image) {
        
        // 占位图片
        self.icon.image = [UIImage imageNamed:@"illness_img_person.png"];
    }
    
}

// 在这个方法中给子控件添加约束
- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@60);
        make.height.equalTo(@60);
        make.left.equalTo(@10);
        make.centerY.equalTo(self);
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon);
        make.left.equalTo(self.icon).offset(70);
    }];
    
    [self.kind mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.name);
        make.left.equalTo(self.name).offset(80);
    }];
    
    [self.hospital mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self.name);
    }];
    
    [self.add mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@10);
        make.height.equalTo(@10);
        make.bottom.equalTo(self.icon);
        make.left.equalTo(self.name);
    }];
    
    [self.addCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.add).offset(10);
        make.bottom.equalTo(self.add).offset(2);
    }];
    
    [self.flower mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@10);
        make.height.equalTo(@10);
        make.bottom.equalTo(self.icon);
        make.left.equalTo(self.addCount).offset(60);
    }];
    
    [self.flowerCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.flower).offset(2);
        make.left.equalTo(self.flower).offset(10);
    }];
    
    [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@10);
        make.height.equalTo(@10);
        make.bottom.equalTo(self.icon);
        make.left.equalTo(self.flowerCount).offset(60);
    }];

    [self.collectCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.icon).offset(2);
        make.left.equalTo(self.collect).offset(10);
    }];
    
    [self.pic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@25);
        make.height.equalTo(@25);
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(- 30 - MOMargin);
    }];
    
    //切圆
    self.icon.layer.cornerRadius = self.icon.bounds.size.height * 0.5;
    self.icon.layer.masksToBounds = YES;
}

#pragma mark -- 各个子控件的懒加载
- (UIImageView *)icon {
    
    if (_icon == nil) {
        _icon = [[UIImageView alloc]init];
    }
    return _icon;
}

- (UILabel *)name {
    
    if (_name == nil) {
        _name = [[UILabel alloc]init];
    }
    return _name;
}

- (UILabel *)kind {
    
    if (_kind == nil) {
        _kind = [[UILabel alloc]init];
    }
    return _kind;
}

- (UILabel *)hospital {
    
    if (_hospital == nil) {
        _hospital = [[UILabel alloc]init];
    }
    return _hospital;
}

- (UIImageView *)pic {
    
    if (_pic == nil) {
        _pic = [[UIImageView alloc]init];
    }
    return _pic;
}

- (UIImageView *)add {
    
    if (_add == nil) {
        _add = [[UIImageView alloc]init];
    }
    return _add;
}

- (UILabel *)addCount {
    
    if (_addCount == nil) {
        _addCount = [[UILabel alloc]init];
    }
    return _addCount;
}

- (UIImageView *)flower {
    
    if (_flower == nil) {
        _flower = [[UIImageView alloc]init];
    }
    return _flower;
}

- (UILabel *)flowerCount {
    
    if (_flowerCount == nil) {
        _flowerCount = [[UILabel alloc]init];
    }
    return _flowerCount;
}

- (UIImageView *)collect {
    
    if (_collect == nil) {
        _collect = [[UIImageView alloc]init];
    }
    return _collect;
}

- (UILabel *)collectCount {
    
    if (_collectCount == nil) {
        _collectCount = [[UILabel alloc]init];
    }
    return _collectCount;
}


@end
